<template>
  <div class="mod-config">
    <table-view ref="view"
                :searchAttrs="searchAttrs"
                :primaryKey="primaryKey"
                :listApiName="listApiName"
                :deleteApiName="deleteApiName"
                :saveAuthName="saveAuthName"
                :deleteAuthName="deleteAuthName"
                :exportApiName="exportApiName"
                :showAttrs="showAttrs"
                :optionWidth="200"
    >
      <template v-slot:foot="{scope}">
        <el-tooltip class="item" effect="dark" content="修改订单状态" placement="bottom" :hide-after="1800"
                    :open-delay="800">
          <el-button type="primary" icon="el-icon-brush" size="small"
                     @click="openOrderStatusDialog(R.prop('row', scope))"></el-button>
        </el-tooltip>
        <!--        <el-tooltip v-if="isAuth(boxOrderAuthName)" class="item" effect="dark" content="导出打样单" placement="bottom" :hide-after="1800" :open-delay="800">-->
        <!--          <el-button size="small" type="text" @click="exportProductProofing(R.path(['row', primaryKey], scope))">-->
        <!--            导出打样单-->
        <!--          </el-button>-->
        <!--        </el-tooltip>-->
        <el-tooltip class="item" effect="dark" content="样品转产品" placement="bottom" :hide-after="1800"
                    :open-delay="800">
          <el-button size="small" type="text" @click="changeProductInfo(R.prop('row', scope))">
            转大货产品
          </el-button>
        </el-tooltip>
      </template>
    </table-view>
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>

    <client-info-add-or-update v-if="clientInfoVisible" ref="clientInfo"></client-info-add-or-update>
    <model-info-add-or-update v-if="modelInfoVisible" ref="modelInfo"></model-info-add-or-update>

    <product-info-add-or-update v-if="productInfoVisible" ref="productInfo"></product-info-add-or-update>

    <el-dialog
      title="选择当前订单的状态"
      :visible.sync="dialogVisible"
      width="30%">
      <el-radio-group v-model="status">
        <el-radio :label="-1">预排</el-radio>
        <el-radio :label="0">待配货</el-radio>
        <el-radio :label="1">暂时下线</el-radio>
        <el-radio :label="2">加急</el-radio>
        <el-radio :label="3">正常</el-radio>
        <el-radio :label="5">完成</el-radio>
        <el-radio :label="90">待确认</el-radio>
        <el-radio :label="99">取消</el-radio>
      </el-radio-group>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="modifyOrderStatus">确 定</el-button>
      </span>
    </el-dialog>
  </div>

</template>

<script>
import AddOrUpdate from '@/views/modules/order/orderproofing-add-or-update'
import tableView from '@/components/tableView'
import basicMixins from '@/utils/commonViewMixins'
import ClientInfoAddOrUpdate from '@/views/modules/client/clientinfo-add-or-update.vue'
import ModelInfoAddOrUpdate from '@/views/modules/model/modelinfo-add-or-update'
import {mRequest} from '@/utils/request'
import {exportHandle, isAuth} from '@/utils'
import productInfoAddOrUpdate from '@/views/modules/product/productinfo-add-or-update'

export default {
  mixins: [basicMixins],
  data() {
    return {
      isAuth: isAuth,
      modifyOrder: null,
      status: 0,
      dialogVisible: false,
      modelInfoVisible: false,
      productInfoVisible: false,
      searchAttrs: {
        clientContractNo:{
          placeholder: '请输入客户合同编号'
        },
        proofingName: {
          label: '打样名称',
          placeholder: '请输入打样名称'
        },
        productWeight: {
          label: '产品重量',
          placeholder: '请输入重量'
        },
        supplierId: {
          label: '供应商名称',
          clearable: true,
          type: 'autoComplete',
          placeholder: '请输入供应商名称',
          querySearchApiName: 'supplierApi/getSupplierList'
        },
        // status: {
        //   label: '状态',
        //   type: 'list',
        //   placeholder: '请输入状态',
        //   list: [
        //     {id: -1, name: '预排产'},
        //     {id: 0, name: '待配货'},
        //     {id: 1, name: '暂时下线'},
        //     {id: 2, name: '加急'},
        //     {id: 3, name: '正常'},
        //     {id: 99, name: '取消'}
        //   ]
        // },
        dateTimeRange: {
          type: 'date',
          dateType: 'daterange',
          clearable: true
        }
      },
      clientInfoVisible: false,
      primaryKey: 'id',
      listApiName: 'orderApi/listOrderProofing',
      deleteApiName: 'orderApi/deleteOrderProofing',
      exportApiName: 'orderApi/exportProductProofingUnFinishedList',
      saveAuthName: 'order:orderproofing:save',
      deleteAuthName: 'order:orderproofing:delete',
      boxOrderAuthName: 'order:orderdetail:boxOrder',
      showAttrs: {
        clientContractNo: {
          label: '客户合同编号', width: 140
        },
        modelNo: {label: '模具编号'},
        proofingName: {label: '打样名称', width: 140},
        customerRequire: {label: '工艺描述', width: 140},
        needPurchaseType: {
          label: '订单模式',
          width: 110,
          type: 'radio',
          items: [
            {value: 0, text: '通货', tagType: 'success'},
            {value: 1, text: '现模'},
            {value: 2, text: '开模', tagType: 'danger'}
          ]
        },
        productCategoryId: {
          label: '产品类型',
          type: 'radio',
          width: 110,
          items: [
            {value: 1, text: '光瓶', tagType: 'success'},
            {value: 23, text: '纸箱', tagType: 'danger'},
            {value: 25, text: '礼盒', tagType: 'danger'},
            {value: 3, text: '喷头', tagType: 'success'},
            {value: 4, text: '中套'},
            {value: 5, text: '披肩', tagType: 'warning'},
            {value: 6, text: '塑料盖', tagType: 'warning'},
            {value: 7, text: '锌合金盖', tagType: 'danger'},
            {value: 8, text: '香薰棒', tagType: 'danger'},
            {value: 9, text: '树脂盖', tagType: 'success'},
            {value: 11, text: '深加工', tagType: 'danger'},
            {value: 66, text: '滚珠', tagType: 'info'},
            {value: 77, text: '电化铝盖', tagType: 'warning'},
            {value: 88, text: '软管类', tagType: 'info'},
            {value: 99, text: '其它', tagType: 'danger'},
            {value: 100, text: '配件'},
            {value: 111, text: '拉管玻璃瓶'},
            {value: 999, text: '标牌', tagType: 'info'},
            {value: 666, text: '木头竹子盖'},
            {value: 888, text: '膏霜罐'},
            {value: 8888, text: '小喷雾乳液泵', tagType: 'success'},
            {value: 88888, text: '香水樽', tagType: 'warning'},
            {value: 888888, text: '塑料瓶'}
          ]
        },
        calibrator: {label: '口径'},
        chargeStatus: {
          label: '收费情况',
          type: 'radio',
          items: [
            {value: 0, text: '免费', tagType: ''},
            {value: 1, text: '收费', tagType: 'success'}
          ]
        },
        unitPrice: {label: '价格'},
        number: {label: '数量'},
        weightStr: {label: '克数'},
        // bottleCraft: {label: '工艺',width:140},
        remark: {label: '备注', width: 140},
        volumeScopeStr: {label: '容量'},
        // clientName: {label: '客户'},
        proofingTime: {label: '打样时间', type: 'date'},
        // deviceId: {
        //   label: '上机',
        //   type: 'radio',
        //   items: [
        //     {value: 1, text: '1#-8单', tagType: 'danger'},
        //     {value: 2, text: '2#-8S',tagType: 'success'},
        //     {value: 3, text: '3#-8S'},
        //     {value: 4, text: '4#-9S',tagType: 'success'},
        //     {value: 5, text: '5#-8S',tagType: 'warning'},
        //     {value: 99, text: '待分配' ,tagType: 'info'},
        //     {value: 100, text: '外发' ,tagType: 'info'}
        //   ]
        // },
        supplierName: {label: '供应商'},

        salesperson: {
          label: '销售'
        },
        modelProofingStatus: {
          label: '试样模是否到位',
          type: 'radio',
          items: [
            {value: 0, text: '未到位', tagType: 'danger'},
            {value: 1, text: '到位', tagType: 'success'}
          ]
        },
        changeProductInfo: {
          label: '是否已转大货',
          type: 'radio',
          width: 120,
          items: [
            {value: 0, text: '未转为大货', tagType: 'danger'},
            {value: 1, text: '已转为大货', tagType: 'success'}
          ]
        },
        productDrawingId: {label: '图纸', showKey: 'proofingName', type: 'file', width: 140},
        status: {
          label: '状态',
          type: 'radio',
          width: 65,
          items: [
            {value: -1, text: '预排产', tagType: 'danger'},
            {value: 0, text: '待配货', tagType: 'info'},
            {value: 1, text: '供应商待确定', tagType: 'info'},
            {value: 2, text: '加急', tagType: 'warning'},
            {value: 3, text: '正常', tagType: 'primary'},
            {value: 99, text: '取消', tagType: 'danger'}
          ]
        }
      }
    }
  },
  components: {
    AddOrUpdate,
    ClientInfoAddOrUpdate,
    ModelInfoAddOrUpdate,
    productInfoAddOrUpdate,
    tableView
  },
  mounted() {
   // this.showSearchStatus()
  },
  methods: {
    showSearchStatus() {
      this.searchAttrs.status.list = [
        {id: -1, name: '预排产'},
        {id: 0, name: '待配货'},
        {id: 1, name: '暂时下线'},
        {id: 2, name: '加急'},
        {id: 3, name: '正常'},
        {id: 99, name: '取消'}
      ]
    },
    openOrderStatusDialog(order) {
      this.dialogVisible = true
      this.modifyOrder = order
      const {status} = order

      this.status = status
    },
    modifyOrderStatus() {
      if (this.modifyOrder.status === this.status) {
        return
      }
      this.modifyOrder.status = this.status

      mRequest('orderApi/updateOrderProofing', this.modifyOrder, () => {
        this.modifyOrder = null
        this.status = 0
        this.dialogVisible = false
        this.getDataList()
      })
    },
    openClientInfoDialog(cb) {
      this.clientInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.clientInfo)) {
          this.$refs.clientInfo.init(null, {status: 1}, cb)
        }
      })
    },
    exportProductProofing(id) {
      exportHandle('orderApi/getProductProofingExport', {id: id})
    },
    openModelInfoDialog(cb) {
      this.modelInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.modelInfo)) {
          this.$refs.modelInfo.init(null, {status: 1}, cb)
        }
      })
    },
    changeProductInfo(orderProofing) {
      // this.productInfoVisible = true

      // this.$nextTick(() => {
      //   if (!this.R.isNil(this.$refs.productInfo)) {
      //     this.$refs.productInfo.init(null, {
      //       productNo: orderProofing.proofingName,
      //       modelId: orderProofing.modelId,
      //       productWeight: this.R.equals(0,orderProofing.realWeight) ? orderProofing.weight : orderProofing.realWeight,
      //       weightScope: orderProofing.weightScope,
      //       bottleOutDiameter: orderProofing.calibrator,
      //       productVolume: this.R.equals(0,orderProofing.realVolume) ? orderProofing.volume : orderProofing.realVolume,
      //       volumeScope: orderProofing.volumeScope,
      //       clientId: orderProofing.clientId,
      //       productImageId: orderProofing.productImageId,
      //       productDrawingId: orderProofing.productDrawingId,
      //       status: 1
      //     }, orderProofing)
      //   }
      // })
    }
  }
}
</script>
